import request from '@/utils/request'

type Common<T> = {
  code: string
  data: T
  mesg: string
  time: string
}

// 获取资源列表
export type ResourceCategoryItem = {
  createdBy: string
  createdTime: string
  description: string
  id: number
  name: string
  operatorId: number | null
  selected: boolean
  sort: number
  updatedBy: string
  updatedTime: string
}

export const getResourceCategoryAll = () => {
  return request<Common<ResourceCategoryItem[]>>({
    method: 'GET',
    url: '/boss/resource/category/getAll'
  })
}

// 保存或更新资源类别
type TResourceCategoryInfo = {
  id?: number
  name: string
  sort: number
}
export const saveOrUpdateResourceCategory = (ResourceCategoryInfo: TResourceCategoryInfo) => {
  return request<Common<boolean>>({
    method: 'POST',
    url: '/boss/resource/category/saveOrderUpdate',
    data: ResourceCategoryInfo
  })
}

// 删除资源类别
export const deleteResourceCategory = (id: number) => {
  return request<Common<boolean>>({
    method: 'DELETE',
    url: `/boss/resource/category/${id}`
  })
}
